<template>
  <div>
    <el-row>
      <el-col>
        <el-form :inline="true" :model="formInline">
          <el-form-item class="dateStyle">
            <el-date-picker
                    size="mini"
                    v-model="formInline.startTime"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="请选择开始日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-select clearable size="mini" v-model="formInline.status" placeholder="请选择状态">
              <el-option label="已归还" value="1"></el-option>
              <el-option label="未归还" value="0"></el-option>
              <el-option label="启用" value="1"></el-option>
              <el-option label="禁用" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="search">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="4">
        <el-tree accordion highlight-current :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      </el-col>
      <el-col :span="20">
        <el-table
                :data="tableData"
                size="mini"
                border
                style="width: 100%">
          <el-table-column
                  align="center"
                  prop="USERNAME"
                  width="100px"
                  label="预约人">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="CLASSIFICATIONNAME"
                  width="300px"
                  label="归类属性">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="STARTTIME"
                  label="预约日期">
            <template slot-scope="scope">
              {{new Date(scope.row.STARTTIME).toLocaleString()}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="ENDTIME"
                  label="结束日期">
            <template slot-scope="scope">
              {{new Date(scope.row.ENDTIME).toLocaleString()}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="CREATETIME"
                  label="创建日期">
            <template slot-scope="scope">
              {{new Date(scope.row.CREATETIME).toLocaleString()}}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                background
                layout="total, sizes, prev, pager, next, jumper"
                :page-size="pagination.pageSize"
                :total="pagination.total"
                :page-sizes="[10, 20, 30, 50, 100]"
        >
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: "equipmentListLog",
    data() {
      return{
        classesName: '',
        name: '',
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}],
        dialogImageUrl: '',
        dialogVisible: false,
        dialogFormVisible3: false,
        form: {
          selectList: [
            {num: '', type: ''}
          ]
        },
        form3: {},
        dialogFormVisible: false,
        form2:{
          deviceName: [ {name: ''}, {num: 1212}]
        },
        formLabelWidth: '100px',
        dialogFormVisible2: false,
        formInline: {},
        pagination: {
          pageSize: 20,
          total: 1,
          pageNo: 1
        },
        data: [],
        defaultProps: {
          children: 'list',
          label: 'NAME'
        },
        tableData: [],
        tableVal: [],
        selectList: [],
        numList: [],
        btnDisabled: false
      }
    },
    created() {
      this.getData(this.pagination.pageSize, this.pagination.pageNo);
      this.getTreeData()
    },
    methods: {
      getTreeData() {
        this.$post('/public/findStructureByTestAppointment').then(res => {
          this.data = res.data.data;
        })
      },
      search() {
        this.$post('/insrtumentAppointment/findInstrumentAppointment', {
          pageSize:this.pagination.pageSize,
          pageNo: 1,
          startTime: this.formInline.startTime,
        }).then(res => {
          if(res.data.status != 1) {
            this.$message.error('条件输入错误，请检查');
            return;
          }
          this.pagination.total = res.data.data.total;
          this.tableData = res.data.data.dataList;
        })
      },
      getData(pageSize, pageNo) {
        this.$post('/insrtumentAppointment/findInstrumentAppointment', {pageSize, pageNo, userId: this.$store.getters.getUserMessage.id}).then(res => {
          this.tableData = res.data.data.dataList;
          this.pagination.total = res.data.data.total;
        })
      },
      valNum(val, newVal) {
        if(newVal > val) {
          this.$message.error('库存不足，请重新输入');
          this.btnDisabled = true
        } else {
          this.btnDisabled = false
        }
      },
      submit() {
        console.log(this.form);
        this.$refs['form'].validate((valid) => {
          if (valid) {
            let classification = [];
            for(let i = 0; i < this.form.selectList.length; i++) {
              classification.push(this.form.selectList[i].type.ID + '|' + this.form.selectList[i].num)
            }
            this.$post('/insrtumentAppointment/add',
                    {
                      startTime: this.form.startTime,
                      endTime: this.form.endTime,
                      classification: classification.join()
                    }).then(res => {
              if(res.data.status === 1) {
                this.$message.success('预约成功');
                this.dialogFormVisible = false;
              } else {
                this.$message.error(res.data.msg)
              }
            })
          } else {
            return false;
          }
        })
        //this.dialogFormVisible = false
      },
      handleSizeChange(size) {
        this.pagination.pageSize = size;
        this.getData(size, this.pagination.pageNo);
      },
      handleCurrentChange(page) {
        this.pagination.pageNo = page;
        this.getData(this.pagination.pageSize, page);
      },
      handleSelectionChange(val) {
        this.tableVal = val;
      },
      //添加选项
      addType() {
        this.form.selectList.push({ num: "", type: '' });
      },
      removeType(i) {
        this.form.selectList.splice(i, 1);
      },
      handleNodeClick(data) {
        console.log(data);
      },
    }
  }
</script>

<style scoped lang="scss">
  .search{
    margin-bottom: 10px;
  }
  /deep/.el-select{
    width: 100%;
  }
  .addDev {
    /deep/.el-form-item__content {
      display: flex;
    }
  }
  /deep/.el-divider{
    background: #409eff;
  }
  /deep/.el-divider__text{
    font-size: 18px;
    color: #409eff;
  }
  /deep/.el-date-editor.el-input, .el-date-editor.el-input__inner {
    width: 100%
  }
  /deep/.el-form-item__error {
    top: 32px;
  }
  .dateStyle{
    /deep/.el-input__inner {
      padding-left: 30px !important;
    }
  }
</style>
